<?php
/**
 * Created by JetBrains PhpStorm.
 * User: GMC
 * Date: 10/3/13
 * Time: 2:20 PM
 * To change this template use File | Settings | File Templates.
 */

class WidgetNewProduct extends CWidget {
    public $products, $category;

    public function init() {
        if ($this->category == 'computer') {
            $id = 10;
        } else {
            $id = 12;
        }
        $products = Product::model()->findAll(array(
            'select' => 'product_id, product_name, description, cat_id, image_id, price, currency, location, add_time, views, user_id, user_name',
            'condition' => 'cat_id = :id and (published  = 1 or status = 1)',
            'order' => 'product_id desc',
            'limit' => 2,
            'params' => array(':id' => $id)
        ));
        $this->products = $products;

    }

    public function run() {
        return CWidget::render('widgetNewProduct', array('model' => $this->products));
    }
}